<?php

namespace common\repositories\cms;

use Yii;
use common\repositories\BaseRepository;
use common\entities\cms\ArticleOrgEntity;

class ArticleOrgRepository extends BaseRepository {

    public static $CHECK_ORG_DIRS = ['99988','99990','99989','99985']; // 发布
    
    public function __construct($config = []) {
        parent::__construct($config);
    }


    public function batchAdd($articleId,$orgGuids) {
        $rows=[];
        foreach ($orgGuids as $orgGuid){
            $rows[]=[$articleId,$orgGuid];
        }
        $conn=ArticleOrgEntity::getDb();
        return $conn->createCommand()->batchInsert(ArticleOrgEntity::tableName(),['article_id','org_guid'],$rows)->execute();
    }
    public function delByArticleId($articleId) {
        if(empty($articleId)){
            return false;
        }
        return ArticleOrgEntity::deleteAll(['article_id'=>$articleId]);
    }
    public function getOrgIdsBy($articleId) {
        if(empty($articleId)){
            return [];
        }
        $result=ArticleOrgEntity::find()->where(['article_id'=>$articleId])->all();
        $orgGuids=[];
        if(!empty($result)){
            foreach ($result as $value) {
                $orgGuids[] = $value->org_guid;
            }
        }
        return $orgGuids;
    }
}